package com.moons.uvcdemo;

import java.io.File;
import java.util.List;

import android.util.Log;


public class StorageUtils {
    public final static String TAG = "StorageUtils";
    public final static int SEARCH_DEEPTH = 3;
    public final static int MIN_FILE_COUNT = 3;
    
    protected final int mSearchDeepth;
    protected final int mMinFileCount;
    
    public StorageUtils() {
    	mSearchDeepth = SEARCH_DEEPTH;
    	mMinFileCount = MIN_FILE_COUNT;
    }
    
    public StorageUtils(int searchDeepth, int minFileCount) {
    	mSearchDeepth = searchDeepth;
    	mMinFileCount = minFileCount;
    }

    public boolean checkAvailableByFileCounts(final String path, final int unmountedMode) {
    	 Log.e(TAG, "checkAvailableByFileCounts(), mounted path: [" + path + "]");
        return checkAvailableByFileCounts(path, unmountedMode, mMinFileCount);
    }

    public boolean checkAvailableByFileCounts(final String path, final int unmountedMode, final int fileCount) {
        // check the file path is exists

        if (! MYFileUtils.isExists(new File(path))) {
            Log.e(TAG, "checkAvailableByFileCounts(), mounted path: [" + path + "] is not exists");
            return false;
        }

//        Log.e(TAG,"###FileUtils.getFileMode()=="+MYFileUtils.getFileMode(path) + "unmountedMode=="+unmountedMode);
//        if (MYFileUtils.getFileMode(path) == unmountedMode) {
//
//            return false;
//        }

        try {
            final List<String> list = MYFileUtils.getFileList(path, mSearchDeepth);
            Log.e(TAG,"###list.size()111=="+list.size());
            if (list.size() > (fileCount - 1)) {
            	Log.e(TAG,"###list.size()=="+list.size());
                return true;
            } else {
                return false;
            }
        } catch (Exception e){
        	Log.e(TAG, "checkAvailableByFileCounts(), mounted path: [" + path + "] exception: " + e.getMessage());
            e.printStackTrace();
            return false;
        }
    }
}